package com.runvp.rest.biz;

import com.runvp.common.annotation.Log;
import com.runvp.common.annotation.ParamValid;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.core.page.TableDataInfo;
import com.runvp.common.enums.BusinessType;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.service.biz.domain.BizPayRecord;
import com.runvp.service.biz.service.IBizPayRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支付请求记录Controller
 * 
 * @author runvp
 * @date 2023-05-25
 */
@Controller
@RequestMapping("/biz/payrecord")
public class BizPayRecordController extends BaseController {
    private String prefix = "biz/payrecord";

    @Autowired
    private IBizPayRecordService bizPayRecordService;

    @RequiresPermissions("biz:payrecord:view")
    @GetMapping()
    public String payrecord() {
        return prefix + "/payrecord";
    }

    /**
     * 查询支付请求记录列表
     */
    @RequiresPermissions("biz:payrecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizPayRecord bizPayRecord) {
        startPage();
        List<BizPayRecord> list = bizPayRecordService.selectBizPayRecordList(bizPayRecord);
        return getDataTable(list);
    }

    /**
     * 导出支付请求记录列表
     */
    @RequiresPermissions("biz:payrecord:export")
    @Log(title = "支付请求记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizPayRecord bizPayRecord) {
        List<BizPayRecord> list = bizPayRecordService.selectBizPayRecordList(bizPayRecord);
        ExcelUtil<BizPayRecord> util = new ExcelUtil<BizPayRecord>(BizPayRecord.class);
        return util.exportExcel(list, "支付请求记录数据");
    }

    /**
     * 新增支付请求记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存支付请求记录
     */
    @ParamValid
    @RequiresPermissions("biz:payrecord:add")
    @Log(title = "支付请求记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizPayRecord bizPayRecord) {
        return toAjax(bizPayRecordService.insertBizPayRecord(bizPayRecord));
    }

    /**
     * 修改支付请求记录
     */
    @RequiresPermissions("biz:payrecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizPayRecord bizPayRecord = bizPayRecordService.selectBizPayRecordById(id);
        mmap.put("bizPayRecord", bizPayRecord);
        return prefix + "/edit";
    }
    /**
     * 支付请求记录详情
     */
    @RequiresPermissions("biz:payrecord:edit")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        BizPayRecord bizPayRecord = bizPayRecordService.selectBizPayRecordById(id);
        mmap.put("bizPayRecord", bizPayRecord);
        return prefix + "/detail";
    }
    /**
     * 修改保存支付请求记录
     */
    @ParamValid
    @RequiresPermissions("biz:payrecord:edit")
    @Log(title = "支付请求记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizPayRecord bizPayRecord) {
        return toAjax(bizPayRecordService.updateBizPayRecord(bizPayRecord));
    }

    /**
     * 删除支付请求记录
     */
    @RequiresPermissions("biz:payrecord:remove")
    @Log(title = "支付请求记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizPayRecordService.deleteBizPayRecordByIds(ids));
    }
}
